home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / update~4.z / update~4 / lib_stdio_freopen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  1.0 KB  |  45 lines

  1. /*                f r e o p e n
  2.  *
  3.  * Open the named file and associate it with the stream indicated.
  4.  * The type of the stream is interpreted in the same manner as
  5.  * for fopen(). The original stream is closed using fclose()
  6.  * regardless of whether the open succeeds or not.
  7.  *
  8.  * The function returns a pointer to the stream on success, otherwise
  9.  * it returns NULL.
  10.  *
  11.  * Patchlevel 1.0
  12.  *
  13.  * Edit History:
  14.  */
  15.  
  16. #include "stdiolib.h"
  17.  
  18. /*LINTLIBRARY*/
  19.  
  20. FILE *freopen(name, mode, fp)
  21.  
  22. CONST char *name;                /* name to open */
  23. CONST char *mode;                /* mode to open with */
  24. FILE       *fp;                    /* stream */
  25.  
  26. {
  27.   int fd;                /* opened file descriptor */
  28.   short flags;                /* flag settings */
  29.   int close();                /* close a channel */
  30.   void free();                /* free memory */
  31.  
  32. /* Close this stream */
  33.   (void) fflush(fp);
  34.   (void) close(fp->_file);
  35.  
  36. /* Free any buffers */
  37.   if (TESTFLAG(fp, _IOMYBUF))
  38.     free((void *) fp->_base);
  39.  
  40. /* Open according to the specified mode */
  41.   return (fd = _fopen(name, mode, -1, &flags)) == -1
  42.     ? NULL
  43.     : _file(fp, fd, flags);
  44. }
  45.